import baseservice from './baseservice.js';
export default {
	getPageData(self, successBack, errorBack) {
		baseservice.getPageData(self, self.apis.customerPage, self.searchcondition);
	},
	getAll(self, successBack, errorBack) {
		self.httptool.ajaxPost(self.apis.customerAll, {}, successBack);
	},
	getModelData(self, id, successBack, errorBack) {
		baseservice.getModelData(self, self.apis.customerGet, id, function(res) {
			if(res.data != null) {
				self.modelData = res.data;
				if(self.modelData.headImg.indexOf("http:") <= -1)
					self.modelData.headImgUrl = self.globaldata.imgBaseUrl + self.modelData.headImg;
				if(self.modelData.investTags) {
					self.selectedtags = self.modelData.investTags.split(',');
				}
			}
		});
	},
	showDetail(self, row, title) {
		baseservice.showDetail(self, row, title);
	},
	handleSave(self, successBack, errorBack) {
		if(self.selectedtags)
			self.modelData.investTags = self.selectedtags.join(',');
		let rule = [{
			name: 'realName',
			label: '投资人名称',
			rule: ['validateEmpty_']
		}, {
			name: 'companyId',
			label: '投资机构',
			rule: ['validateSelect_']
		}, {
			name: 'tel',
			label: '手机号',
			rule: ['validateEmpty_', 'validateTel_']
		}, {
			name: 'career',
			label: '职位',
			rule: ['validateEmpty_']
		}, {
			name: 'email',
			label: '邮箱',
			rule: ['validateEmpty_', 'validateEmail_']
		}];

		if(!self.validatetool.validate(self, self.modelData, rule)) {
			return;
		}
		debugger;
		let requestUrl = self.apis.customerAdd;
		let msg = '添加成功';
		if(self.modelData.id > 0) {
			requestUrl = self.apis.customerUpdate;
			msg = '修改成功';
		}
		baseservice.handleSave(self, requestUrl, self.modelData, msg);
	},
	updateStatus(self, id, status) {
		let that = this;
		let params = {
			id: id,
			status: status == "trade_fid" ? "trade_user" : "trade_fid"
		}
		self.$confirm('确定要' + (status == "trade_fid" ? "启用该客户吗？" : "禁用该客户吗？"), '提示', {
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			type: 'warning'
		}).then(() => {
			self.httptool.ajaxPost(self.apis.updateStatus, params, function(res) {
				that.getPageData(self);
			});
		}).catch(() => {

		});

	}
}